package com.arpa.ntocc.common.service.impl;

import cn.hutool.core.util.IdUtil;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.ntocc.common.domain.dto.ResourceUserColDTO;
import com.arpa.ntocc.common.domain.entity.ResourceUserCol;
import com.arpa.ntocc.common.domain.vo.ResourceUserColVO;
import com.arpa.ntocc.common.mapper.ResourceUserColMapper;
import com.arpa.ntocc.common.service.IResourceUserColService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户菜单列表字段 服务实现类
 * </p>
 *
 * @author liuyj
 * @since 2019-11-25
 */
@Service
public class ResourceUserColServiceImpl extends ServiceImpl<ResourceUserColMapper, ResourceUserCol> implements IResourceUserColService {

    /**
     * 保存
     * @param entity
     * @return
     */
    @Override
    public boolean save(ResourceUserCol entity) {
        if(StringUtils.isBlank(entity.getCode())){
            entity.setCode(IdUtil.simpleUUID());
        }
        if(StringUtils.isBlank(entity.getCreatedBy())){
            entity.setCreatedBy(UserUtil.getCode());
        }
        return super.save(entity);
    }

    /**
     * 根据code更新实体
     * @param entity
     * @return
     */
    @Override
    public int updateByCode(ResourceUserCol entity) {
        if(StringUtils.isBlank(entity.getModifiedBy())){
            entity.setModifiedBy(UserUtil.getCode());
        }
        return baseMapper.update(entity,new QueryWrapper<ResourceUserCol>().lambda().eq(ResourceUserCol::getCode,entity.getCode()));
    }

    /**
     * 查询列表
     * @param resourceUserColDTO
     * @return
     */
    @Override
    public List<ResourceUserColVO> queryList(ResourceUserColDTO resourceUserColDTO){
        List<ResourceUserColVO> resourceUserColVOList = baseMapper.queryList(resourceUserColDTO);
        return resourceUserColVOList;
    }

    /**
     * 查询合计,包含总数
     * @param resourceUserColDTO
     * @return
     */
    @Override
    public ResourceUserColVO queryListSum(ResourceUserColDTO resourceUserColDTO){
        ResourceUserColVO resourceUserColVO = baseMapper.queryListSum(resourceUserColDTO);
        return resourceUserColVO;
    }

}
